package yl.hs.bmipfull.controllers.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.system.ISearchViewService;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/*
 * SearchViewsController
 * @category
 * @author 谢景广
 * @date 2021-10-23
 */
@Api(value = "功能过滤条件", tags = "系统管理——功能视图管理")
@RequestMapping(path = "/api/system")
@RestController
public class SearchViewsController extends ControllerBase {
    @ApiOperation(value = "保存搜索条件", notes = "保存搜索条件")
    @RequestMapping(path = "views", method = RequestMethod.POST)
    @ResponseBody
    public WebResult saveSearchView(@RequestBody SubmitModel model){
        try{
            svSvc.saveViewModel(model);
            return success("ok");
        }
        catch (Exception ee){
            return error(ee);
        }
    }
    @ApiOperation(value = "保存搜索条件", notes = "保存搜索条件")
    @RequestMapping(path = "view_filters", method = RequestMethod.POST)
    @ResponseBody
    public WebResult saveSearchViewFilters(@RequestBody SubmitModel model){
        try{
            svSvc.saveViewFilter(model);
            return success("ok");
        }
        catch (Exception ee){
            return error(ee);
        }
    }

    @ApiOperation(value = "保存搜索条件", notes = "保存搜索条件")
    @RequestMapping(path = "view_fields", method = RequestMethod.POST)
    @ResponseBody
    public WebResult saveSearchViewFields(@RequestBody SubmitModel model){
        try{
            svSvc.saveViewFields(model);
            return success("ok");
        }
        catch (Exception ee){
            return error(ee);
        }
    }
    @ApiOperation(value = "保存搜索条件", notes = "保存搜索条件")
    @RequestMapping(path = "view/{SN}",
            method = RequestMethod.DELETE)
    @ResponseBody
    public WebResult deleteView(@PathVariable("SN") String SN){
        try{
            svSvc.deleteView(SN);
            return success("ok");
        }
        catch (Exception ee){
            return error(ee);
        }
    }
    @Autowired
    ISearchViewService svSvc;
}
